<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
	<meta name="renderer" content="webkit" />
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<meta name="apple-mobile-web-app-title" content="" />
	<meta name="format-detection" content="telephone=no,email=no,adress=no" />
	<link rel="stylesheet" type="text/css" href="css/test.css" />
	<script type="text/javascript" src="js/jquery-3.2.1.js"></script>
	<title>评价管理系统</title>
	<style>
		html,
		body {
			width: 100%;
			height: 100%;
			overflow: auto;
		}

		body {
			background: url(images/bg.png) no-repeat left top;
			background-size: 100%;
		}
		#arrow-icon {
			transition: all .3s;
		}
	</style>
</head>


<body class="homeBg">
	<header class="headTop">
		<p>评价管理系统</p>
	</header>
	<section class="contentNei">
		<!-- 内容开始 -->
		<article class="homeCenter">
			<figure class="zhong" onclick="login()">
				<img src="images/user.png">
				<figcaption>管理员登录</figcaption>
			</figure>

			<!-- 02 -->
			<div class="homeJie">
				<hgroup>
					<h6 id="organName">机构名</h6>
					<p>
						<span id="organInfo">简介</span>
					</p>
				</hgroup>
				<figure class="center zhong">
					<figcaption>更多</figcaption>
					<img id="arrow-icon" src="images/go.png">
				</figure>
			</div>

			<!-- 03 -->
			<div class="homeRule">
				<div class="homeRuleTxt">•　评价规则　•</div>

				<div class="homeRuleWhite">
					<!-- 中间的连接符 -->
					<div class="homeRuleLian"><img src="images/line.png"></div>
					<div class="homeRuleLianRight"><img src="images/line.png"></div>
					<ul>
						<li class="zhong">
							<hgroup class="zhong">
								<h6>1</h6>
								<p>评价项点：</p>
							</hgroup>
							<dl class="homeRuleDl" id='appraiseItem'>

							</dl>
						</li>
						<li class="zhong">
							<hgroup class="zhong">
								<h6>2</h6>
								<p>测评次数：<span>每人每天只可参与测评1次</span></p>
							</hgroup>
						</li>
						<li class="zhong">
							<hgroup class="zhong">
								<h6>3</h6>
								<p>测评方式：<span>扫码测评</span></p>
							</hgroup>
						</li>
						<li class="zhong">
							<hgroup class="zhong">
								<h6>4</h6>
								<p>测评格次：<span>满意、一般、不满意</span></p>
							</hgroup>
						</li>
					</ul>
				</div>

				<!-- 02 -->
				<div class="homeRuleWhite">
					<div class="homeRulePic">
						<img src="images/txt.png">
						<ul>
							<li onclick="satisfied(0)">
								<figure>
									<i></i>
									<figcaption>满意</figcaption>
								</figure>
							</li>
							<li onclick="satisfied(1)">
								<figure>
									<i></i>
									<figcaption>一般</figcaption>
								</figure>
							</li>
							<li onclick="satisfied(2)">
								<figure>
									<i></i>
									<figcaption>不满意</figcaption>
							</li>
						</ul>
					</div>
				</div>
				<div style="margin:10px;color:#fff">
					如有建议请联系qq:
					<a style="color:#93a9e8" href="tencent://Message/?Uin=564924487&amp;websiteName=q-zone.qq.com&amp;Menu=yes" target="_blank">
						1045838275
					</a>
					
			</div>

		</article>



	</section>


	<script type="text/javascript">	
		var baseUrl = 'https://wjjj.utools.club/api';
		localStorage.setItem('baseUrl', baseUrl);
		var todayDate = new Date();
		var yesterdayDate = new Date();
		yesterdayDate.setDate(yesterdayDate.getDate() - 1)
		
		var today = todayDate.getFullYear()+todayDate.getMonth()+todayDate.getDate();
		var yesterday = yesterdayDate.getFullYear()+yesterdayDate.getMonth()+yesterdayDate.getDate();
		console.log("昨天",yesterday)
		console.log("今天",today)
		
		var organId = parseInt(location.search.substring(1).split('=')[1])
		$.ajax({
			url: baseUrl + '/organ',
			data: {
				id: organId
			},
			success: function (res) {
				console.log(res);
				if (res.code === 200) {
					var organ = res.data.organ;
					// 将改机构缓存
					localStorage.setItem("organ", JSON.stringify(organ));
					$('#organName').html(organ.organName);
					$('#organInfo').html(organ.organInfo);
					console.log("高度",$('#organInfo').height());
					if($('#organInfo').height() <= 72) {
						$('.homeJie').find('figure').hide();
					}else {
						$('.homeJie').find('figure').show();
					}
					var appraiseNames = organ.appraiseNames.split(',');
					var ddlist = [];
					for (var i = 0; i < appraiseNames.length; i++) {
						ddlist.push(`<dd>${appraiseNames[i]}</dd>`)
					}
					$('#appraiseItem').html(ddlist.join(""))
				}
			}
		})
		// 0满意 1一般 2不满意
		function satisfied(appraiseType) {
			var appraiseArr = JSON.parse(localStorage.getItem('appraise'));
			var tempArr = [];
			var isAppraise = false;
			if(appraiseArr){
				for(var i=0;i<appraiseArr.length;i++){
					var item = appraiseArr[i];
					if(item.time==today){
						tempArr.push(item);
					}
					if(item.time==today && item.organId==organId){
						isAppraise = true;
					}
				}
				localStorage.setItem("appraise",JSON.stringify(tempArr))
			}
			if(isAppraise){
				alert("今日已评价")
				return;
			}
			if(appraiseType==2){
				$(window).attr('location', 'homeDetails.html?id=' + organId)
				return;
			}
			$.ajax({
				url: baseUrl + '/appraise',
				method: 'put',
				data: {
					organId: organId,
					appraiseType: appraiseType
				},
				success: function (res) {
					console.log(res);
					if (res.code === 200) {
						//时间+机构id+评价等级（0满意 1一般 2不满意）
						var appraise = {
							time:today,
							organId:organId,
							choose:appraiseType
						}
						tempArr.push(appraise)
						localStorage.setItem('appraise',JSON.stringify(tempArr))
						$(window).attr('location', 'succeed.html');
					}
				}
			})
		}
		function login() {
			$(window).attr('location', 'login.html');
		}

		$(function () {
			$('.homeJie>figure').click(function () {
				if ($(this).find('figcaption').html() == '更多') {
					$('#arrow-icon').css('transform','rotate(180deg)');
					$(this).find('figcaption').html('收起');
					$('.homeJie>hgroup p').css('display', 'block');
				} else if ($(this).find('figcaption').html() == '收起') {
					$('#arrow-icon').css('transform','rotate(0deg)');
					$(this).find('figcaption').html('更多');
					$('.homeJie>hgroup p').css('display', '-webkit-box');
				}
			})
		})
	</script>

</body>

</html>